package com.oscar.ehome.view.pageview.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.base.C;
import com.oscar.ehome.bean.pagebean.ClassRoomBean;
import com.oscar.ehome.provider.gildeimage.GildeUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/9/15
 */

public class ClassoomAdapter extends BaseAdapter {

    private List<ClassRoomBean.ClassRoomListBean> dataList = new ArrayList<>();
    private LayoutInflater mInflater;
    private Context mContext = null;
    ClassRoomBean.ClassRoomListBean bean;

    public ClassoomAdapter(Context context, List<ClassRoomBean.ClassRoomListBean> list) {
        this.mContext = context;
        this.dataList = list;
        mInflater = LayoutInflater.from(context);
    }

    public void setList(List<ClassRoomBean.ClassRoomListBean> list) {
        this.dataList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adapter_classroom, null);
            holder = new ViewHolder();
            holder.classroom_image = (ImageView) convertView.findViewById(R.id.classroom_image);
            holder.classrom_text = (TextView) convertView.findViewById(R.id.classrom_text);
            holder.classroom_title = (TextView) convertView.findViewById(R.id.classroom_title);
            holder.classroom_context = (TextView) convertView.findViewById(R.id.classroom_context);
            convertView.setTag(holder); //
        } else {
            holder = (ViewHolder) convertView.getTag(); //
        }

        if (dataList.size() > 0) {
            bean = dataList.get(position);
            if (bean != null) {
                if (bean.getCreateBy() != null) {
                    if (bean.getCreateBy().getName() != null) {
                        holder.classroom_context.setText(bean.getCreateBy().getName());
                    }
                } else {
                    holder.classroom_context.setText("暂无");
                }
                if (bean.getTitle() != null) {
                    holder.classroom_title.setText(bean.getTitle());
                }
//                if (bean.get() != null) {
//                    holder.classrom_text.setText(bean.getContent());
//                }
                if (bean.getCoverPicture() != null) {
//                    GildeUtils.imgLoadPic(mContext, C.qiniu + bean.getCoverPicture(), holder.classroom_image, "net");
                    GildeUtils.loadUrlImages(C.qiniu + bean.getCoverPicture(), holder.classroom_image, mContext);
                }
            }
        }

        return convertView;
    }

    class ViewHolder {
        ImageView classroom_image;
        TextView classrom_text;
        TextView classroom_title;
        TextView classroom_context;
    }

}
